import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateContentDto } from './dto/create-content.dto';
import { UpdateContentDto } from './dto/update-content.dto';

import { Content as ContentEntity } from './entities/content.entity';
import { Classify as ClassifyEntity } from './entities/classify.entity';
@Injectable()
export class ContentService {
  
  constructor(
    @InjectRepository(ContentEntity)
    private readonly contentRepository: Repository<ContentEntity>,
    @InjectRepository(ClassifyEntity)
    private readonly classifyRepository: Repository<ClassifyEntity>,
  ) {}

  async create(createContentDto: CreateContentDto) {
    return await this.contentRepository.save(createContentDto);
  }

  async findAll(): Promise<ContentEntity[]> {
    return await this.contentRepository.find();
  }

  async findOne(id: number) {
    return await this.contentRepository.findOne(id);
  }

  async update(id: number, updateContentDto: UpdateContentDto) {
    return await this.contentRepository.update(id,updateContentDto);
  }

  async remove(id: number) {
    return await this.contentRepository.delete(id);
  }

  async findAllClassify(): Promise<ClassifyEntity[]> {
    return await this.classifyRepository.find();
  }
}
